﻿using System;
using System.Runtime.CompilerServices;
using Core.Base.UI;
using Core.Mgr._EventSys;
using UnityEngine;
using UnityEngine.UI;

namespace Logic.Global.UI
{
    [UI("LoadUI", EUIType.TopCanvas, false, EScreenMatchMode.Height)]
    public class LoadUI : BaseUI
    {
        public Slider slider;
        private float _curProgress = 0;

        public override void OnInit(UIAttribute uiAttribute)
        {
            base.OnInit(uiAttribute);
            this.RegHandler(ELoadUI.OnUpdateProgress, OnUpdateProgress);
        }

        public override void OnOpen(ITuple tuple = null)
        {
            base.OnOpen(tuple);
            slider.value = 0;
        }

        private void Update()
        {
            slider.value = Mathf.Lerp(slider.value, _curProgress, Time.deltaTime * 10);
        }

        private void OnUpdateProgress(ITuple obj)
        {
            _curProgress = ((ValueTuple<float>) obj).Item1;
        }
    }
}